﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IBMS.Common;

namespace IBMS.Page
{
    public partial class UserModify : System.Web.UI.Page
    {
        private User modifyUser = new User();
        private User user = new User();
        private DB db = new DB();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserModification"] != null)
                {
                    modifyUser = (User)Session["UserModification"];
                    this.username.Text = modifyUser.Name;
                    //this.oldPassword.Text = modifyUser.Password;
                    this.DropDownList1.SelectedValue = modifyUser.UserType;
                    //switch (modifyUser.UserType)
                    //{
                    //    case "SuperAdmin":
                    //        this.DropDownList1.SelectedValue = "超级管理员";
                    //        break;
                    //    case "AuthorizedUser":
                    //        this.DropDownList1.SelectedValue = "授权用户";
                    //        break;
                    //    case "ExaminationUser":
                    //        this.DropDownList1.SelectedValue = "审查用户";
                    //        break;
                    //    default:
                    //        break;
                    //}
                }
            }
            
        }

        protected void btn_zhuce_Click(object sender, EventArgs e)
        {
            if (Session["UserModification"] != null)
            {
                modifyUser = (User)Session["UserModification"];
            }
            if (IsValid)
            {
                user.Name = this.username.Text.ToString();
                user.Password = user.MD5(this.password.Text.ToString());
                user.UserType = this.DropDownList1.SelectedItem.Value.ToString();
                db.ExecuteNonQury("update Users set Name='"+user.Name+"', Password='"+user.Password+"', UserType='"+user.UserType+"'where ID="+modifyUser.Id);
                Response.Redirect("AllUsersList.aspx");
            }
        }
    }
}